﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_doctor : System.Web.UI.Page
{
    protected Administrator admin;
    int guid;
    public Doctor doc;
    protected void Page_Load(object sender, EventArgs e)
    {
        admin = Administrator.Check();
        if (admin == null)
        {
            Session.Add(Params.SystemError, "请先登录");
            Response.Redirect(Params.RootHttp + "default.aspx");
        }
        this.guid = Convert.ToInt32(Request.Params["guid"]);
        this.doc = new Doctor(guid);
        if (!Page.IsPostBack)
        {
            this.MyDataBind();
        }
    }

    private void MyDataBind()
    {
        this.conNav.Title = "导师-" + this.doc.RealName;
        this.Title = "管理员-浏览导师-" + this.doc.RealName;
        this.tbEmail.Text = doc.Email;
        this.tbName.Text = doc.RealName;
        this.tbYjfx.Text = doc.Yjfx;
        this.labID.Text = doc.UserID;
        this.labPaperNum.Text = doc.PaperCount.ToString();
        this.labStuNum.Text = doc.StudentCount.ToString();
        this.hlDoctor.NavigateUrl = Params.DoctorFolderHttp + "default.aspx?uid="+Server.UrlEncode(doc.UserID);
        this.ddTeam.DataSource = Team.Teams(false);
        this.ddTeam.DataBind();
        this.ddTeam.SelectedValue = this.doc.TeamGuid.ToString();
        this.ddCategory.DataSource = Category.Categorys(false);
        this.ddCategory.DataBind();
        this.ddCategory.SelectedValue = this.doc.CategoryGuid.ToString();
        this.cbExpert.Checked = this.doc.Expert;
        this.tbMaxPaperNUm.Text = this.doc.MaxPaperNum.ToString();
        this.tbMinPaperNUm.Text = this.doc.MinPaperNum.ToString();

        this.btnDelete.Attributes.Add("onclick", "return confirm('确定删除该导师以及所有相关数据？')");
        this.btnResetPwd.Attributes.Add("onclick", "return confirm('确定重置密码为导师的ID？')");

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string n = this.tbName.Text.Trim();
        string email = this.tbEmail.Text.Trim();
        string yjfx = this.tbYjfx.Text;
        int tg = Convert.ToInt32(this.ddTeam.SelectedValue);
        int cg = Convert.ToInt32(this.ddCategory.SelectedValue);
        bool exp = this.cbExpert.Checked;
        string minP = this.tbMinPaperNUm.Text.Trim();
        string maxP = this.tbMaxPaperNUm.Text.Trim();
        if (n == "")
        {
            this.info.SetMessage("姓名不能为空！");
            return;
        }
        if((!Fun.IsNumeric(minP))||(!Fun.IsNumeric(maxP)))
        {
            this.info.SetMessage("审阅论文数必须为正整数！");
            return;
        }
        this.doc.RealName = n;
        this.doc.Email = email;
        this.doc.Yjfx = yjfx;
        this.doc.TeamGuid = tg;
        this.doc.CategoryGuid = cg;
        this.doc.MinPaperNum = Convert.ToInt32(minP);
        this.doc.MaxPaperNum = Convert.ToInt32(maxP);
        this.doc.Expert = exp;
        this.doc.Update();
        Session.Add(Params.SystemError, "修改成功");
        Response.Redirect(Request.RawUrl);
    }
}
